package com.action;
import com.po.*;
import com.services.bizServices;

import java.util.*;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.stereotype.Controller;

import com.biz.*;
import com.opensymphony.xwork2.ActionContext;
@Controller
@ParentPackage("struts-default")
@Namespace("/")
public class UsersAction implements IAction {
	private Users us;
	private Integer id;
	private String path;
	
	@Resource(name="bizServices")
	private bizServices	bizService;
	
	public bizServices getBizService() {
		return bizService;
	}

	public void setBizService(bizServices bizService) {
		this.bizService = bizService;
	}
	public Users getUs() {
		return us;
	}

	public void setUs(Users us) {
		this.us = us;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	
	@Action(value="save_Users", results={
			@Result(name="ok", location="${path}", type="redirect")
	})
	public String save() {
		boolean flag=bizService.getUsersBiz().save(us);
		if(flag){
			path="findPageAll_Users";
			return "ok";
		}
			
		return "fail";
	}
	@Action(value="update_Users", results={
			@Result(name="ok", location="${path}", type="redirect")
	})
	public String update() {
		boolean flag=bizService.getUsersBiz().update(us);
		if(flag){
			path="findPageAll_Users";
			return "ok";
		}
		return null;
	}
	@Action(value="delById_Users", results={
			@Result(name="ok", location="${path}", type="redirect")
	})
	public String delById() {
		boolean flag=bizService.getUsersBiz().delById(id);
		if(flag){
			path="findPageAll_Users";
			return "ok";
		}
		return null;
	}
	@Action(value="findById_Users", results={
			@Result(name="ok", location="${path}", type="redirect")
	})
	public String findById() {
		Users oldus=bizService.getUsersBiz().findById(id);
		ActionContext.getContext().getSession().put("oldus",oldus);
		path="users.jsp";
		return "ok";
	}
	@Action(value="findPageAll_Users", results={
			@Result(name="ok", location="${path}", type="redirect")
	})
	public String findPageAll() {
		List<Users> lsus=bizService.getUsersBiz().findAll();
		ActionContext.getContext().getSession().put("lsus",lsus);
		path="users.jsp";
		return "ok";
	}
	@Action(value="check_Users",results={
			@Result(name="ok",location="${path}",type="redirect")
	})
	public String check(){
		System.out.println("aaaaaaaaaaaaaa");
		Users nus=bizService.getUsersBiz().check(us);
		System.out.println("eeeeeeeeeeee");
		if(nus!=null){
			ActionContext.getContext().getSession().put("nus",nus);
			List<Dep> lsdep = bizService.getDepBiz().findAll();
			List<Welfare> lswf = bizService.getWelfareBiz().findAll();
			ActionContext.getContext().getSession().put("lsdep", lsdep);
			ActionContext.getContext().getSession().put("lswf", lswf);
			path="main.jsp";
		}else{
			path="login.jsp?error=1";
		}
		
		return "ok";
	}

}
